//
//  CPHudController.swift
//  CJPackDemo
//
//  Created by 陈警卫 on 2023-12-07.
//

import UIKit
import CJPack

class CPHudController: CJBaseBackController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let hubB1 = UIButton(type: .custom)
        hubB1.frame = CGRect(x: 20, y: CJScreen.navBatBarHeight + 10, width: 200, height: 30)
        hubB1.backgroundColor = CPColor.vistaModel.color
        hubB1.setTitle("show text loading", for: .normal)
        hubB1.setTitleColor(CPColor.foreModel.color, for: .normal)
        hubB1.addTarget(self, action: #selector(hubB1Action(btn:)), for: .touchUpInside)
        view.addSubview(hubB1)
        
        let hubB2 = UIButton(type: .custom)
        hubB2.frame = CGRect(x: 20, y: hubB1.cj_bottom + 10, width: 200, height: 30)
        hubB2.backgroundColor = CPColor.vistaModel.color
        hubB2.setTitle("show text", for: .normal)
        hubB2.setTitleColor(CPColor.foreModel.color, for: .normal)
        hubB2.addTarget(self, action: #selector(hubB2Action(btn:)), for: .touchUpInside)
        view.addSubview(hubB2)
        
        let hubB3 = UIButton(type: .custom)
        hubB3.frame = CGRect(x: 20, y: hubB2.cj_bottom + 10, width: 200, height: 30)
        hubB3.backgroundColor = CPColor.vistaModel.color
        hubB3.setTitle("show loading", for: .normal)
        hubB3.setTitleColor(CPColor.foreModel.color, for: .normal)
        hubB3.addTarget(self, action: #selector(hubB3Action(btn:)), for: .touchUpInside)
        view.addSubview(hubB3)
        
    }

}

extension CPHudController {
    
    @objc func hubB1Action(btn: UIButton) {
        let hud = CJHuder.showing(toView: view, text: "提示提示提示提示提示提示提示提示提示提示提示提示提示提示")
        DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
            hud?.hide()
        }
    }
    
    @objc func hubB2Action(btn: UIButton) {
        CJHuder.showText(text: "提示提示提示提示提示提示提示提示提示提示提示提示提示提示")
    }
    
    @objc func hubB3Action(btn: UIButton) {
        let hud = CJHuder.showing(toView: view)
        DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
            hud?.hide()
        }
    }
    
}
